package com.nku.mason.scm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.nku.mason.scm.vo.SysParam;

@Service("sysParamService")
public class SysParamServiceImpl extends BaseServiceImpl<SysParam> implements SysParamService {

	@Override
	public Map<String, Map<String, Object>> loadSysParam(SysParam sysParam) {
		List<SysParam> lists = sysParamMapper.selectList(sysParam);
		// 存放所有的字段类型
		Map<String, Map<String, Object>> sysParamMap = new HashMap<String, Map<String, Object>>();
		// 用来存放字段对应的值
		Map<String, Object> fieldMap = null;
		for (SysParam s : lists) {
			if (("1").equals(s.getSysParamType())) {
				System.out.println("-------------" + s.getSysParamValue() + "----------");
				List<SysParam> sps = sysParamMapper.selectOtherTable(s.getSysParamValue());
				fieldMap = new HashMap<String, Object>();
				for (SysParam sp : sps) {
					System.out.println("-----------sysParam------------" + sp);
					fieldMap.put(sp.getSysParamValue(), sp.getSysParamText());
				}
				sysParamMap.put(s.getSysParamField(), fieldMap);
				fieldMap = null;
			} else {
				if (sysParamMap.get(s.getSysParamField()) == null) {
					fieldMap = new HashMap<String, Object>();
					fieldMap.put(s.getSysParamValue(), s.getSysParamText());
					sysParamMap.put(s.getSysParamField(), fieldMap);
					fieldMap = null;
				} else {
					fieldMap = sysParamMap.get(s.getSysParamField());
					fieldMap.put(s.getSysParamValue(), s.getSysParamText());
					fieldMap = null;
				}
			}

		}

		return sysParamMap;

	}

}
